package ui;

import java.awt.ComponentOrientation;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.sql.SQLException;

import javax.swing.Box;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

/**
 * The MenuBar of the CalendarUI
 * 
 * @author Sean Young
 * @version 1.0
 *
 */
public class MenuBar extends JMenuBar {
	
	private JMenu file, newFile, editFile; 
	private JMenuItem createNewCal, createNewEvent, editCal, editEvent, export, exportTo, exit;
	private MenuBarListener listener;
	private CalendarUI parent;
	
	/**
	 * Constructor for the MenuBar. Requires a reference to 
	 * Main Panel.
	 * @param parent The main panel
	 */
	public MenuBar(CalendarUI parent){
		super();
		
		this.parent = parent;
		listener = new MenuBarListener();
		
		file = new JMenu("File");
		this.add(file);
		
		newFile = new JMenu("New");
		newFile.setMnemonic(KeyEvent.VK_C);
		file.add(newFile);
		
		createNewCal = new JMenuItem("Calendar");
		createNewCal.addActionListener(listener);
		createNewCal.setActionCommand("newCalendar");
		newFile.add(createNewCal);
		
		createNewEvent = new JMenuItem("Event");
		createNewEvent.addActionListener(listener);
		createNewEvent.setActionCommand("newEvent");
		newFile.add(createNewEvent);
		
		/*editFile = new JMenu("Edit");
		editFile.setMnemonic(KeyEvent.VK_C);
		file.add(editFile);
		
		editCal = new JMenuItem("Calendar");
		editCal.addActionListener(listener);
		editCal.setActionCommand("editCalendar");
		editFile.add(editCal);
		
		editEvent = new JMenuItem("Event");
		editEvent.addActionListener(listener);
		editEvent.setActionCommand("editEvent");
		editFile.add(editEvent);*/

		export = new JMenuItem("Export");
		export.addActionListener(listener);
		export.setActionCommand("export");
		file.add(export);
		
		exportTo = new JMenuItem("Export To");
		exportTo.addActionListener(listener);
		exportTo.setActionCommand("exportTo");
		file.add(exportTo);
		
		exit = new JMenuItem("Exit");
		exit.addActionListener(listener);
		exit.setActionCommand("exit");
		file.add(exit);
	}

	/**
	 * Listener for the MenuBar. Performs actions based upon the 
	 * menu item selected.
	 *
	 */
	public class MenuBarListener implements ActionListener{
		
		@Override
		public void actionPerformed(ActionEvent e) {
			
			switch(e.getActionCommand()){
				case "newCalendar": parent.changePanel("Create Calendar Panel");
					break;
				case "newEvent": parent.changePanel("Create Event Panel");
					break;
				case "exportTo": parent.exportPath();
					break;
				case "export": parent.export();
					break;
				case "exit": parent.exit();
					break;
			}
		}
	}
				
}
